package com.gjt.zyglxt.controller;

import java.util.HashMap;
import java.util.List; 
import java.util.Map;

import javax.annotation.Resource;

import com.gjt.zyglxt.dao.IReadroomDao;
import com.gjt.zyglxt.model.Readroom;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * ReadroomController
 */
@RestController
@RequestMapping("/readroom")
public class ReadroomController {

    @Resource
    private IReadroomDao readroomDao;

    @ApiOperation(value = "查询所有",notes = "查询所有")
    @GetMapping("/findAll")
    public Map<String,Object> findAll(){
        List<Readroom> list = readroomDao.findAll();
        Map<String,Object> map=new HashMap<String ,Object>();
        map.put("code", 0);
        map.put("msg", "查询成功");
       map.put("count",list.size() ); 
        map.put("data",list); 
        return map;
    }
    

    @ApiOperation(value = "添加资源",notes = "添加资源")
    @PostMapping("/addOredit")
    public Readroom add(@RequestBody Readroom r){
        return readroomDao.save(r);
    }
  

    @ApiOperation(value = "根据id删除",notes = "根据id删除")
    @ApiImplicitParam(name = "id",value = "主键",required = true,paramType = "path")
    @DeleteMapping("/{id}")
    public void del(@PathVariable Integer id){
        readroomDao.deleteById(id);
    }
}